﻿Imports DTO
Imports System.Data.SqlClient

Public Class BanDAO
    Public Function LayDanhSachBanDAO() As List(Of BanDTO)
        Dim _listBanDTO As New List(Of BanDTO)
        Dim _dsBan As DataTable = DataProvider.LoadSQL("select * from BAN where isdel = 0")

        For Each row As DataRow In _dsBan.Rows
            Dim maBan As Integer = Integer.Parse(row(0).ToString())
            Dim loai As Integer = Integer.Parse(row(1).ToString())
            Dim tinhTrang As Integer = Integer.Parse(row(2).ToString())
            Dim banDTO As New BanDTO(maBan, loai, tinhTrang)

            _listBanDTO.Add(banDTO)
        Next
        Return _listBanDTO
    End Function

    Public Function LayTableBanDAO() As DataTable
        Dim _dsBan As New DataTable()
        _dsBan = DataProvider.LoadSQL("select * from BAN where isdel = 0")
        Return _dsBan
    End Function


    Public Function LayThongTinBanDAO(ByVal maBan As Integer) As BanDTO
        Dim ban As DataTable = DataProvider.LoadSQL("Select * from BAN where MaBan = " & maBan)
        Dim row As DataRow = ban.Rows(0)
        Dim Loai As Integer = Integer.Parse(row(1).ToString())
        Dim TinhTrang As Integer = Integer.Parse(row(2).ToString())
        Dim _banDTO As New BanDTO(maBan, Loai, TinhTrang)
        Return _banDTO
    End Function

    Public Function CapNhatTrangThaiBanDangSuDungDAO(ByVal _banDTO As BanDTO) As Integer
        Dim sql = "sp_CapNhatTrangThaiBanDangSuDung"
        Dim _listPara As New List(Of SqlParameter)

        Dim MaBan As New SqlParameter("@MaBan", SqlDbType.Int)
        MaBan.Value = _banDTO.MaBan
        _listPara.Add(MaBan)

        Dim MaHD As New SqlParameter("@MaHD", SqlDbType.Int)
        MaHD.Direction = ParameterDirection.Output
        _listPara.Add(MaHD)

        DataProvider.ExcuteQueryProc(sql, _listPara)

        Return MaHD.Value
    End Function

#Region "Thêm xoá sửa bàn"

    Public Sub ThemBanDAO(ByVal _loai As Integer)
        Dim sql As String = "sp_ThemBan"

        Dim _listPara As New List(Of SqlParameter)

        Dim Loai As New SqlParameter("@Loai", SqlDbType.Int)
        Loai.Value = _loai
        _listPara.Add(Loai)

        DataProvider.ExcuteQueryProc(sql, _listPara)
    End Sub

    Public Sub SuaBanDAO(ByVal _maBAn As Integer, ByVal _loai As Integer)
        Dim sql As String = "sp_SuaBan"

        Dim _listPara As New List(Of SqlParameter)

        Dim MaBan As New SqlParameter("@MaBan", SqlDbType.Int)
        MaBan.Value = _maBAn
        _listPara.Add(MaBan)

        Dim Loai As New SqlParameter("@Loai", SqlDbType.Int)
        Loai.Value = _loai
        _listPara.Add(Loai)

        DataProvider.ExcuteQueryProc(sql, _listPara)

    End Sub

    Public Sub XoaBanDAO(ByVal _maBan As Integer)
        Dim sql As String = "sp_XoaBan"

        Dim _listPara As New List(Of SqlParameter)

        Dim MaBan As New SqlParameter("@MaBan", SqlDbType.Int)
        MaBan.Value = _maBan
        _listPara.Add(MaBan)

        DataProvider.ExcuteQueryProc(sql, _listPara)

    End Sub
#End Region
End Class
